using System;
using System.Xml;

namespace ECCIT.Configuration
{
	/// <summary>
	/// </summary>
	public class LanguageManager : ConfigManager
	{
		internal enum LanguageType
		{
			Chinese,
			English,
		}
		
		internal class Language
		{
			public static readonly LanguageType Type = LanguageType.Chinese;
			public static readonly string DirName = "zh-cn";
		}
		
		private const string LanguagesDirName = "Languages";

		private string _nameSpace;
		private string _className;
		private string _language;
		private XmlDocument _configDoc;

		public LanguageManager(string applicationPath, string language, string nameSpace, string className) : base(applicationPath)
		{
			_nameSpace = nameSpace;
			_className = className;
			_language = language;

			this.ConfigFileName = LanguagesDirName + @"\" + _language + @"\" + _nameSpace + ".config";

			_configDoc = GetConfigDocument();
		}

		public string GetValue(string key)
		{
			string returnValue = string.Empty;
			XmlNode classNode = _configDoc.DocumentElement.SelectSingleNode("./class[@name='" + _className + "']");
			if( classNode != null )
			{
				XmlNode addNode = classNode.SelectSingleNode("./add[@key='" + key + "']");
				if(addNode != null)
					returnValue = addNode.Attributes.GetNamedItem("value").InnerText;
			}

			return returnValue;
		}
	}
}
